﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.ComponentModel;

namespace Bubbels.Helper
{

    public class PositionConverter : IValueConverter
    {
        [DefaultValue(true)]
        public bool IsRowConverter { get; set; }

        [DefaultValue(0)]
        public int Row{get;set;}

        [DefaultValue(0)]
        public int Col { get; set; }

        public double Width { get; set; }
        public double Height { get; set; }

        public PositionConverter()
        {
            this.Row = 0;
            this.Col = 0;
        }
        public PositionConverter(bool rowConverter, int row, int col):this()
        {
            this.Row = row;
            this.Col = col;
            this.IsRowConverter = rowConverter;
        }
        public PositionConverter(bool rowConverter)
        {

            this.IsRowConverter = rowConverter;
        }
        public double BallSize { get { return Width / Col > Height / Row ? Height / Row : Width / Col; } }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double ballSize = BallSize;

            int row = (int)value;
            if (null !=parameter)
            {
                IsRowConverter =System.Convert.ToBoolean( parameter);
            }
            if (IsRowConverter)
            {
                return (this.Row - row - 1) * ballSize;

            }
            return row * ballSize;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
